package com.usermanage.controller;

import com.ordercore.Util.ResponseData.ResponseData;
import com.pinza.Bean.NonStandardLibraryBean;
import com.pinza.Common.NonStandardLibraryIOC;
import com.pinza.Common.SkuIOC;
import com.usermanage.Service.ContractRealTimePriceService;
import com.usermanage.Service.SkuEosService;
import com.usermanage.beanParam.ContractRealTimePriceBean;
import com.usermanage.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * SKU数据操作接口
 * serachSkuList    根据组查询组下合作sku
 * addSku   添加合作SKU
 * isSku    验证SKU是否存在
 */
@Api(description = "SKU数据操作接口")
@RestController
@RequestMapping("/sku")
public class SkuEosController {


    @Resource
    private SkuEosService skuEosService;

    /**
     * 根据组id查询组下的合作对象
     *
     * @param groupId
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "根据组查询组下合作sku", notes = "根据组查询组下合作sku")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/serachSkuList", method = RequestMethod.GET)
    public JsonData serachSkuList(@RequestParam("groupId") String groupId) throws Exception {
        //根据登陆用户的groupId查询出组织合作的sku列表
        List list = skuEosService.serachSkuList(groupId);

        //调用sku接口获取sku详情
        //返回数据列表
        return JsonData.success(list);
    }

    /**
     * 根据组id添加合作SKU
     *
     * @param skuId
     * @param groupId
     * @param groupId 组id
     * @return
     */
    @ApiOperation(value = "添加合作SKU", notes = "添加合作SKU")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuId", value = "skuId", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/addSku", method = RequestMethod.POST)
    public JsonData addSku(@RequestParam("skuId") String skuId, @RequestParam("groupId") String groupId) {
        //调用SkuController中的isSku方法，若存在提示存在信息，若不存在则实现插入操作。
        //验证sku是否存在，返回true表示存在，false表示不存在
        boolean bool = skuEosService.isSku(skuId, groupId);
        if (!bool) {//表示sku不存在，可以插入
            skuEosService.add(skuId, groupId);
        }
        return JsonData.success();
    }


    @ApiOperation(value = "根据组id,skuId,定额id添加定额详情", notes = "根据组id,skuId，定额id添加定额详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "quotaId", value = "定额id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "skuId", value = "skuId", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/addSkuQuota", method = RequestMethod.POST)
    public JsonData addSkuQuota(@RequestParam("groupId") String groupId, @RequestParam("skuId") String skuId, @RequestParam("quotaId") String quotaId) {
        //为sku添加一个定额
//        int result = quotaService.addSkuQuota(groupId,skuId,quotaId);
//        if (result == 0){
//            return JsonData.fail("定额添加失败，系统异常。");
//        }
        return JsonData.success();
    }


    @ApiOperation(value = "验证SKU是否存在", notes = "验证SKU是否存在")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "skuId", value = "skuId", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "groupId", value = "组id", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/isSku", method = RequestMethod.GET)
    public JsonData isSku(@RequestParam("skuId") String skuId, @RequestParam("groupId") String groupId) {
        //查询验证sku是否存在，存在返回true，不存在返回false
        boolean bool = skuEosService.isSku(skuId, groupId);
        return JsonData.success(bool);
    }

}
